package com.app.util;

import com.app.enums.StatusCodeEnum;
import lombok.Data;
import org.bouncycastle.asn1.OIDTokenizer;

import java.io.Serializable;

@Data
public class Result<T> implements Serializable {
    private Integer code;
    private String msg;
    private T data;


    public static <T>Result<T>success(T data) {
        return Result.success(StatusCodeEnum.STATUS200.getMsg(),data);
    }
    public static <T>Result<T>success() {
        return Result.success(StatusCodeEnum.STATUS200.getMsg(),null);
    }
    public static <T> Result<T> success(String msg,T data) {
        Result<T> result = new Result<>();
        result.setCode(StatusCodeEnum.STATUS200.getCode());
        result.setMsg(msg);
        if(data!=null)
        {
            result.setData(data);
        }
        return result;
    }


    public static Result<Object> error(Integer code, String msg) {
        Result<Object> result = new Result<>();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }
}